package tablefactory;

import factory.Item;
import factory.Tray;

import java.util.Iterator;

public class TableTray extends Tray {
    public TableTray(String caption) {
        super(caption);
    }

    @Override
    public String makeHtml() {
        StringBuilder builder = new StringBuilder();
        builder.append("<td>\n");
        builder.append("<table width=\"100%\" border=\"1\"><tr>");
        builder.append("<td bgcolor=\"#cccccc\" align=\"center\" colspan=\""+tray.size()+"\">"+caption+"</td></tr>\n");
        builder.append("<tr>\n");
        Iterator<Item> iterator = tray.iterator();
        while (iterator.hasNext()){
            Item item = iterator.next();
            builder.append(item.makeHtml());
        }
        builder.append("</tr>\n");
        builder.append("</table>\n");
        builder.append("</td>\n");
        return builder.toString();
    }
}
